<template>
	<view>
		<!-- 地址 -->
		<navigator url="/package/address/address?source=1" class="address-section">
			<view class="order-content">
				<text class="yticon icon-shouhuodizhi"></text>
				<view class="cen">
					<view class="top">
						<text class="name">{{addressData.name}}</text>
						<text class="mobile">{{addressData.phone}}</text>
					</view>
					<text class="address">{{addressData.province}} {{addressData.city}} {{addressData.county}} {{addressData.detail}}</text>
				</view>
				<text class="yticon icon-you"></text>
			</view>

			<image class="a-bg" src=""></image>
		</navigator>

		<view class="goods-section">
			<view class="g-header b-b"> 
			<van-icon class="logo" name="shop-o" />
				<text class="name">营昕居</text>
			</view>
			<!-- 商品列表 -->
			<view class="g-item">
				<image v-if="listinfo.avatarUrl" :src="listinfo.avatarUrl"></image>
				<image v-else :src="listinfo.mainImage"></image>
				<view class="right">
					<text v-if="listinfo.nick" class="title clamp">{{infotype}}-{{listinfo.nick}}</text>
					<text v-else class="title clamp">{{infotype}}-{{listinfo.provideServiceUserNick}}</text>
					<text class="spec">{{couponList.title}}</text>
					<view class="price-box">
						<text class="price">{{couponList.price}}</text>
					</view>
					<van-stepper class="caty-steper" :value="1" v-model="formdata.number" disable-input integer @change="onChange" /> 
				</view>
			</view>
		</view>

		<!-- 金额明细 -->
		<view class="yt-list">
			<view class="yt-list-cell b-b">
				<text class="cell-tit clamp">商品金额</text>
				<text class="cell-tip">{{couponList.price}}</text>
			</view>
			<view class="yt-list-cell b-b"> 
				<text class="cell-tit clamp">运费</text>
				<text class="cell-tip">免运费</text>
			</view>
			<view class="yt-list-cell desc-cell">
				<text class="cell-tit clamp">服务项目</text>
				<input class="desc" type="text" v-model="test" placeholder="请选择服务项目" placeholder-class="placeholder" />
			</view>
			<view class="yt-list-cell desc-cell">
				<text class="cell-tit clamp">备注</text>
				<input class="desc" type="text" v-model="desc" placeholder="请填写备注信息" placeholder-class="placeholder" />
			</view>
			<view class="cell-ylti">
				<text>{{couponList.desc}}</text>
			</view>
		</view>
		
		<!-- 底部 -->  
		<view class="footer">
			<view class="price-content">
				<text>实付款</text>
				<text class="price-tip">￥</text>
				<text class="price">{{couponList.price*formdata.number}}</text>
			</view>
			<text class="submit" @click="submit">提交订单</text>
		</view>

	</view>
</template>

<script>
	import use from '@/http/user.js'
	import employeesConst from '@/employees/employees.js' 
	const hireTypet = {} 
	employeesConst.hireTypecon.forEach((item) => {
	  hireTypet[item.type] = item.value;
	});
	export default {
		 
		data() {
			return {
				orderInfo:{},
				maskState: 0, //优惠券面板显示状态
				desc: '', //备注
				test:'', //服务项目
				couponList: [],
				listinfo:{},
				addressData: {},
				infotype:'',
				//订单
				formdata:{
					 serviceId: "",
					  serviceType: "",
					  price: Number,
					  number: 1,
					  provideServiceUserId: Number,
					  provideServiceUserType: "",
					  remake: "",
					  serviceProject: "",
					  serviceAddress: {
					    name: '', 
					    phone: "",
					    province: "",
					    city: "", 
					    county: "",
					    street: "",
					    detail: ""
					  } 
				}
			}  
		}, 
		onLoad(option){
			//商品数据
			this.loaddcher()
			this.listinfo = JSON.parse(option.data);
			if(!this.listinfo.provideServiceUserType){
				this.infotype = hireTypet[this.listinfo.typeInfos[0].type]
			} else{
				this.infotype = hireTypet[this.listinfo.provideServiceUserType]
			}
		},
		methods: {
			async loaddcher(){
			const res = await use.addorder({"type":'DEFAULT'}) 
			this.couponList = res.data
			// 地址 
			const resd = await use.address()
			for(let i = 0; i<resd.data.length;i++){
				if(resd.data[i].isDefault == true){
					this.addressData = resd.data[i]
				}
			}
			},
			// 提交订单
			async submit(){
				this.formdata.serviceType = this.couponList.serviceType
				this.formdata.price = this.couponList.price
				this.formdata.serviceId = this.couponList.serviceId
				if(!this.listinfo.provideServiceUserType){
				this.formdata.provideServiceUserId = this.listinfo.userId
				this.formdata.provideServiceUserType = this.listinfo.typeInfos[0].type
				} else {
				this.formdata.provideServiceUserId = this.listinfo.provideServiceUserId
				this.formdata.provideServiceUserType = this.listinfo.provideServiceUserType
				}
				this.formdata.remake = this.desc
				this.formdata.serviceProject = this.test
				this.formdata.serviceAddress.phone = this.addressData.phone
				this.formdata.serviceAddress.name = this.addressData.name
				this.formdata.serviceAddress.province = this.addressData.province
				this.formdata.serviceAddress.county = this.addressData.county
				this.formdata.serviceAddress.city = this.addressData.city
				this.formdata.serviceAddress.detail = this.addressData.detail
				this.formdata.serviceAddress.street = this.addressData.detail
				const res = await use.placeanorder(this.formdata)
				uni.redirectTo({
					url: `/package/money/pay?id=${res.data}&price=${this.couponList.price*this.formdata.number}`
				})
			},  
			onChange(event){
				this.formdata.number = event.detail
			}
		}
	}
</script>

<style lang="scss">
	page {
		background: $page-color-base;
		padding-bottom: 100upx;
	}

	.address-section {
		padding: 30upx 0;
		background: #fff;
		position: relative;

		.order-content {
			display: flex;
			align-items: center;
		}

		.icon-shouhuodizhi {
			flex-shrink: 0;
			display: flex;
			align-items: center;
			justify-content: center;
			width: 90upx;
			color: #888;
			font-size: 44upx;
		}

		.cen {
			display: flex;
			flex-direction: column;
			flex: 1;
			font-size: 28upx;
			color: $font-color-dark;
		}

		.name {
			font-size: 34upx; 
			margin-right: 24upx;
			
		}

		.address {
			margin-top: 16upx;
			margin-right: 20upx;
			color: $font-color-light;
		}

		.icon-you {
			font-size: 32upx;
			color: $font-color-light;
			margin-right: 30upx;
		}

		.a-bg {
			position: absolute;
			left: 0;
			bottom: 0;
			display: block;
			width: 100%;
			height: 5upx;
		}
	}

	.goods-section {
		margin-top: 16upx;
		background: #fff;
		padding-bottom: 1px;

		.g-header {
			display: flex;
			align-items: center;
			height: 84upx;
			padding: 0 30upx;
			position: relative;
		}

		.logo {
			display: block;
			width: 50upx;
			height: 50upx;
			border-radius: 100px;
		}

		.name {
			font-size: 30upx;
			color: $font-color-base;
			margin-left: 24upx;
		}

		.g-item {
			display: flex;
			margin: 20upx 30upx;

			image {
				flex-shrink: 0;
				display: block;
				width: 140upx;
				height: 140upx;
				border-radius: 4upx;
			}

			.right {
				flex: 1;
				padding-left: 24upx;
				overflow: hidden;
			}

			.title {
				font-size: 30upx;
				color: $font-color-dark;
			}

			.spec {
				font-size: 26upx;
				color: $font-color-light;
			}

			.price-box {
				display: flex;
				align-items: center;
				font-size: 32upx;
				color: $font-color-dark;
				padding-top: 10upx;

			}

			.step-box {
				position: relative;
			}
		}
	}
	.yt-list {
		margin-top: 16upx;
		background: #fff;
	}

	.yt-list-cell {
		display: flex;
		align-items: center;
		padding: 10upx 30upx 10upx 40upx;
		line-height: 70upx;
		position: relative;

		&.cell-hover {
			background: #fafafa;
		}

		&.b-b:after {
			left: 30upx;
		}

		.cell-icon {
			height: 32upx;
			width: 32upx;
			font-size: 22upx;
			color: #fff;
			text-align: center;
			line-height: 32upx;
			background: #f85e52;
			border-radius: 4upx;
			margin-right: 12upx;

			&.hb {
				background: #ffaa0e;
			}

			&.lpk {
				background: #3ab54a;
			}

		}

		.cell-more {
			align-self: center;
			font-size: 24upx;
			color: $font-color-light;
			margin-left: 8upx;
			margin-right: -10upx;
		}

		.cell-tit {
			flex: 1;
			font-size: 26upx;
			color: $font-color-light;
			margin-right: 10upx;
		}

		.cell-tip {
			font-size: 26upx;
			color: $font-color-dark;

			&.disabled {
				color: $font-color-light;
			}

			&.active {
				color: $base-color;
			}
			&.red{
				color: $base-color;
			}
		}

		&.desc-cell {
			.cell-tit {
				max-width: 150upx;
			}
		}

		.desc {
			flex: 1;
			font-size: $font-base;
			color: $font-color-dark;
		}
	}
	
	/* 支付列表 */
	.pay-list{
		padding-left: 40upx;
		margin-top: 16upx;
		background: #fff;
		.pay-item{
			display: flex;
			align-items: center;
			padding-right: 20upx;
			line-height: 1;
			height: 110upx;	
			position: relative;
		}
		.icon-weixinzhifu{
			width: 80upx;
			font-size: 40upx;
			color: #6BCC03;
		}
		.icon-alipay{
			width: 80upx;
			font-size: 40upx;
			color: #06B4FD;
		}
		.icon-xuanzhong2{
			display: flex;
			align-items: center;
			justify-content: center;
			width: 60upx;
			height: 60upx;
			font-size: 40upx;
			color: $base-color;
		}
		.tit{
			font-size: 32upx;
			color: $font-color-dark;
			flex: 1;
		}
	}
	
	.footer{
		position: fixed;
		left: 0;
		bottom: 0;
		z-index: 995;
		display: flex;
		align-items: center;
		width: 100%;
		height: 90upx;
		justify-content: space-between;
		font-size: 30upx;
		background-color: #fff;
		z-index: 998;
		color: $font-color-base;
		box-shadow: 0 -1px 5px rgba(0,0,0,.1);
		.price-content{
			padding-left: 30upx;
		}
		.price-tip{
			color: $base-color;
			margin-left: 8upx;
		}
		.price{
			font-size: 36upx;
			color: $base-color;
		}
		.submit{
			display:flex;
			align-items:center;
			justify-content: center;
			width: 280upx;
			height: 100%;
			color: #fff;
			font-size: 32upx;
			background-color: $uni-color-primary;
		} 
	}
	
	.cell-ylti{
		margin-left: 35rpx;
		margin-right: 35rpx;
		font-size: 28rpx;
		color: #b5b5b5;
	}
    .caty-steper{
		display: inline-block;
		float: right;
		margin-right: 15rpx;
	}
</style>
